<?php

/*
 * 微商城首页控制器
 * @author <!--blakefan 1621743934@qq.com -->
 */
namespace Home\Controller;
use Think\Controller;
class ItemDetailController extends Controller 
{
	public function index()
	{
		$result='';
		$itemid=I('get.itemid',0,'strip_tags');
		$itemDetail=D('ItemDetail');
		$result=$itemDetail->index();
		$this->assign('iteminfo',$result['iteminfo'][$itemid]);
		$carttotal=!empty($result['carttotal'])?$result['carttotal'][0]['number']:0;
		$this->assign('itemdesc',$result['itemdesc']);
		$this->assign('itemattr',$result['attr']);
		$this->assign('carttotal',$carttotal);
		$this->display();
	}
	/*
	 *获取商品规格
	 *@param itemid 
	 *return json
	 */
	public function getSpec()
	{   
		$result=array();
		$itemid=I('post.itemid',0,'strip_tags');
		if(empty($itemid))
		{  
			$result['status']=0;
			$result['msg']='系统繁忙,请稍后测试';
			echo json_encode($result);
			return '';
		}
		$product=M('product');
		$temp=$product->where('itemid=%d',$itemid)->getField('productid,price,inventory,color');
		if(!empty($temp))
		{
			$result['status']=1;
			$result['products']=array_values($temp);
			echo json_encode($result);
			return '';
		}
		//当商品无规格时
		$result['status']=0;
		$result['products']=array(array(productid=>"0", price=>"0.00", inventory=>"0", color=>"随机"));
		echo json_encode($result);
		return '';
	}
	
}